Repository navigation
feat: show icon instead of channel alias - #199
Conversation
Reviewer's GuideThis PR adds a configurable channel-icon presentation for channel-authored megagroup messages, replacing the alias/custom label with a cached broadcast icon while updating label sizing and conditionally adjusting the related experimental settings UI. Sequence diagram for channel icon renderingsequenceDiagram
participant ChatMessageCell
participant NaConfig
participant TimeStringHelper
participant ContextCompat
participant Theme
participant StaticLayout
ChatMessageCell->>NaConfig: getShowChannelIcon().Bool()
alt icon enabled
ChatMessageCell->>TimeStringHelper: getChannelDrawable()
TimeStringHelper->>ContextCompat: getDrawable(applicationContext, menu_broadcast)
ContextCompat-->>TimeStringHelper: Drawable
TimeStringHelper-->>ChatMessageCell: channelDrawable
ChatMessageCell->>Theme: chat_adminPaint.getTextSize()
ChatMessageCell->>ChatMessageCell: append icon span
else icon disabled
ChatMessageCell->>NaConfig: getCustomChannelLabel().String()
ChatMessageCell->>ChatMessageCell: getChannelAlias(channel_id)
ChatMessageCell->>ChatMessageCell: append alias or channel label
end
ChatMessageCell->>StaticLayout: getLineWidth(0)
StaticLayout-->>ChatMessageCell: adminWidth
Flow diagram for experimental channel label settingsflowchart TD
A[User toggles ShowChannelIcon] --> B[NaConfig.showChannelIcon updates]
B --> C[updateRows]
C --> D{ShowChannelIcon enabled?}
D -->|Yes| E[Hide custom channel label row]
D -->|No| F[Show custom channel label row]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java" line_range="19098-19099" />
<code_context>
- adminString.append(channelStr);
}
- adminWidth = (int) Math.ceil(Theme.chat_adminPaint.measureText(adminString.toString()));
+ StaticLayout staticLayout = new StaticLayout(adminString, Theme.chat_adminPaint, dp(300), Layout.Alignment.ALIGN_NORMAL, 0f, 0f, false);
+ adminWidth = (int) Math.ceil(staticLayout.getLineWidth(0));
nameWidth -= adminWidth;
} else {
</code_context>
<issue_to_address>
**Long labels overlap message content**
When a channel alias or configured label exceeds 300dp, `StaticLayout.getLineWidth(0)` measures only the first wrapped line, making `adminWidth` too narrow and `nameWidth` too large. The label wraps, overlaps the author name, and can spill into message content.
Measure the complete label rather than only the first line when calculating `adminWidth`.
</issue_to_address>
### Comment 2
<location path="TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java" line_range="340-341" />
<code_context>
tooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null);
} else if (key.equals(NaConfig.INSTANCE.getDisableStories().getKey())) {
tooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null);
+ } else if (key.equals(NaConfig.INSTANCE.getShowChannelIcon().getKey())) {
+ updateRows();
}
};
</code_context>
<issue_to_address>
**Bound messages keep stale labels**
When the option changes while messages with the previous label are already bound, `updateRows()` refreshes only the settings list; `ChatMessageCell.setMessageObjectInternal()` has already stored each message label, so bound cells keep showing the old alias or icon until rebound.
Refresh or rebind the visible `ChatMessageCell` instances when the option changes.
</issue_to_address>
### Comment 3
<location path="TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/TimeStringHelper.java" line_range="14" />
<code_context>
public class TimeStringHelper {
public static Drawable forwardsDrawable;
+ public static Drawable channelDrawable;
public static Drawable getForwardsDrawable() {
</code_context>
<issue_to_address>
**Channel icons use wrong colors**
When channel-label spans with different admin colors are drawn in succession, `TimeStringHelper.getChannelDrawable()` returns the same mutable drawable to every `ColoredImageSpan`. A span can change its color filter while another span skips resetting it because its cached tint is unchanged, so icons display the wrong colors.
Return a separate mutated drawable for each span, or reset the drawable’s color filter on every draw.
Also at `TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java:19078-19081`, `TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/TimeStringHelper.java:25-27`.
</issue_to_address>
### Comment 4
<location path="TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java" line_range="340-341" />
<code_context>
tooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null);
} else if (key.equals(NaConfig.INSTANCE.getDisableStories().getKey())) {
tooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null);
+ } else if (key.equals(NaConfig.INSTANCE.getShowChannelIcon().getKey())) {
+ updateRows();
}
};
</code_context>
<issue_to_address>
**Channel label setting stays stale**
When the user changes ShowChannelIcon while the settings screen is open, the toggle handler calls `updateRows()`, but the custom-label row is added or removed only in `setCanNotChange()`. Since the handler does not call that row-management logic, changing the icon setting leaves the custom-label row visible or hidden until the settings screen is rebuilt.
Reapply the custom-label row visibility rule when the setting changes, then refresh the adapter.
Also at `TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java:552-555`.
</issue_to_address>Sourcery assessment
Approval pending. 4 findings to address first.
Blocking findings: TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java:19099, TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java:341, TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/TimeStringHelper.java:14, TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java:341
it looks better imo.
Option disabled:

Option enabled:

just like this pr: #85
Summary by Sourcery
Add configurable channel icons for channel-authored message labels.
New Features:
Enhancements: