IITC.comm

Namespace for comm-related functionalities.

Namespaces

declarativeMessageFilter

Members

static _channels :Array.<chat.ChannelDescription>

static _channelsData :Object

Holds data related to each intel channel.

static dividerTemplate :String

Template for message divider.

static, constant messageTransformFunctions

List of transformations to be applied to the message data. Each transformation function takes the full message data object and returns the transformed markup. The default transformations aim to convert the message markup into an older, more straightforward format, facilitating easier understanding and backward compatibility with plugins expecting the older message format.

Example
// Adding a new transformation function to the array
// This new function adds a "new" prefix to the player's plain text if the player is from the RESISTANCE team
messageTransformFunctions.push((data) => {
  const markup = data.markup;
  if (markup.length > 2 && markup[0][0] === 'PLAYER' && markup[0][1].team === 'RESISTANCE') {
    markup[1][1].plain = 'new ' + markup[1][1].plain;
  }
  return markup;
});

static msgCellTemplate :String

Template for chat message text cell.

static msgRowTemplate :String

Template for message row, includes cells for time, player nickname and message text.

static nickCellTemplate :String

Template for player's nickname cell.

static, constant portalNameTransformations

List of transformations for portal names used in chat. Each transformation function takes the portal markup object and returns a transformed name. If a transformation does not apply, the original name is returned.

Example
// Adding a transformation that appends the portal location to its name
portalNameTransformations.push((markup) => {
  const latlng = `${markup.latE6 / 1E6},${markup.lngE6 / 1E6}`; // Convert E6 format to decimal
  return `[${latlng}] ${markup.name}`;
});

static portalTemplate :String

Template of portal link in comm.

static timeCellTemplate :String

Template for time cell.

Methods

private, static _genPostData(channel, getOlderMsgs, args) → {Object}

Generates post data for chat requests.

Parameters:
Name Type Description
channel string

The chat channel.

getOlderMsgs boolean

Flag to determine if older messages are being requested.

args

Used for backward compatibility when calling a function with three arguments.

Returns:
Object -

The generated post data.

private, static _handleChannel(channel, data, olderMsgs, ascendingTimestampOrder)

Handles faction chat response.

Parameters:
Name Type Description
channel string

Comm Intel channel (all/faction/alerts)

data Object

Response data from server.

olderMsgs boolean

Indicates if older messages were requested.

ascendingTimestampOrder boolean

Indicates if messages are in ascending timestamp order.

private, static _initChannelData(id)

Initialize the channel data.

Parameters:
Name Type Description
id chat.ChannelDescription

The channel id.

private, static _updateOldNewHash(newData, storageHash, isOlderMsgs, isAscendingOrder)

Updates the oldest and newest message timestamps and GUIDs in the chat storage.

Parameters:
Name Type Description
newData Object

The new chat data received.

storageHash Object

The chat storage object.

isOlderMsgs boolean

Whether the new data contains older messages.

isAscendingOrder boolean

Whether the new data is in ascending order.

private, static _writeDataToHash(newData, storageHash, isOlderMsgs, isAscendingOrder)

Writes new chat data to the chat storage and manages the order of messages.

Parameters:
Name Type Description
newData Object

The new chat data received.

storageHash Object

The chat storage object.

isOlderMsgs boolean

Whether the new data contains older messages.

isAscendingOrder boolean

Whether the new data is in ascending order.

static getChatPortalName(markup) → {string}

Overrides portal names used repeatedly in chat, such as 'US Post Office', with more specific names. Applies a series of transformations to the portal name based on the portal markup.

Parameters:
Name Type Description
markup Object

An object containing portal markup, including the name and address.

Returns:
string -

The processed portal name.

static getLatLngForSendingMessage() → {L.LatLng}

Returns the coordinates for the message to be sent, default is the center of the map.

Returns:
L.LatLng

static parseMsgData(data) → {Object}

Parses comm message data into a more convenient format.

Parameters:
Name Type Description
data Object

The raw comm message data.

Returns:
Object -

The parsed comm message data.

static renderChannel(channel, oldMsgsWereAdded)

Renders intel chat.

Parameters:
Name Type Description
channel string

Comm Intel channel (all/faction/alerts)

oldMsgsWereAdded boolean

Indicates if old messages were added in the current rendering.

static renderData(data, element, likelyWereOldMsgs, sortedGuids)

Renders data from the data-hash to the element defined by the given ID.

Parameters:
Name Type Description
data Object

Chat data to be rendered.

element string

ID of the DOM element to render the chat into.

likelyWereOldMsgs boolean

Flag indicating if older messages are likely to have been added.

sortedGuids Array

Sorted array of GUIDs representing the order of messages.

static renderDivider(text) → {string}

Renders a divider row in the chat table.

Parameters:
Name Type Description
text string

Text to display within the divider row.

Returns:
string -

The HTML string representing a divider row in the chat table.

static renderFactionEnt(faction) → {string}

Renders a faction entity for use in the chat.

Parameters:
Name Type Description
faction Object

The faction data.

Returns:
string -

HTML string representing the faction.

static renderMarkup(markup) → {string}

Renders the markup of a chat message, converting special entities like player names, portals, etc., into HTML.

Parameters:
Name Type Description
markup Array

The markup array of a chat message.

Returns:
string -

The HTML string representing the complete rendered chat message.

static renderMarkupEntity(ent) → {string}

Renders a chat message entity based on its type.

Parameters:
Name Type Description
ent Array

The entity array, where the first element is the type and the second element is the data.

Returns:
string -

The HTML string representing the chat message entity.

static renderMsgCell(msg, classNames) → {string}

Renders a cell in the chat table for a chat message. The message is inserted as inner HTML of the table cell.

Parameters:
Name Type Description
msg string

The chat message to be displayed.

classNames string

Additional class names to be added to the message cell.

Returns:
string -

The HTML string representing a table cell with the chat message.

static renderMsgRow(data) → {string}

Renders a row for a chat message including time, nickname, and message cells.

Parameters:
Name Type Description
data Object

The data for the message, including time, player, and message content.

Returns:
string -

The HTML string representing a row in the chat table.

static renderNickCell(nick, classNames) → {string}

Renders a cell in the chat table for a player's nickname. Wraps the nickname in HTML element for highlighting.

Parameters:
Name Type Description
nick string

The nickname of the player.

classNames string

Additional class names to be added to the nickname cell.

Returns:
string -

The HTML string representing a table cell with the player's nickname.

static renderPlayer(player, at, sender) → {string}

Renders a player's nickname in chat.

Parameters:
Name Type Description
player Object

The player object containing nickname and team.

at boolean

Whether to prepend '@' to the nickname.

sender boolean

Whether the player is the sender of a message.

Returns:
string -

The HTML string representing the player's nickname in chat.

static renderPortal(portal) → {string}

Renders a portal link for use in the chat.

Parameters:
Name Type Description
portal Object

The portal data.

Returns:
string -

HTML string of the portal link.

static renderText(text) → {string}

Renders text for the chat, converting plain text to HTML and adding links.

Parameters:
Name Type Description
text Object

An object containing the plain text to render.

Returns:
string -

The rendered HTML string.

static renderTimeCell(unixtime, classNames) → {string}

Renders a cell in the chat table to display the time a message was sent. Formats the time and adds it to a

Parameters:
Name Type Description
unixtime number

The timestamp of the message.

classNames string

Additional class names to be added to the time cell.

Returns:
string -

The HTML string representing a table cell with the formatted time.

static requestChannel(channel, getOlderMsgs, isRetryopt)

Requests chat messages.

Parameters:
Name Type Attributes Default Description
channel string

Comm Intel channel (all/faction/alerts)

getOlderMsgs boolean

Flag to determine if older messages are being requested.

isRetry boolean <optional>
false

Flag to indicate if this is a retry attempt.

static sendChatMessage(tab, msg)

Posts a chat message to intel comm context.

Parameters:
Name Type Description
tab string

intel tab name (either all or faction)

msg string

message to be sent

static transformMessage(data) → {Object}

Applies transformations to the markup array based on the transformations defined in the IITC.comm.messageTransformFunctions array. Assumes all transformations return a new markup array. May be used to build an entirely new markup to be rendered without altering the original one.

Parameters:
Name Type Description
data Object

The data for the message, including time, player, and message content.

Returns:
Object -

The transformed markup array.